from typing import Annotated
from pydantic import BaseModel, Field, field_validator, validators

from fastapi import APIRouter, Depends, Path, Query

user = APIRouter()


class PageQuery(BaseModel):
    page: Annotated[int, Query(ge=1, le=100)] = 1
    page_size: Annotated[int, Query(ge=1, le=100)] = 10


class User(BaseModel):
    name: str = Field()
    age: int
    address: str
    friends: list[str]

    @field_validator("age")
    def check_age(cls, v):
        if v < 18:
            raise ValueError("must be over 18")
        return v
    

@user.post("/")
def get_users(page: Annotated[PageQuery, Depends(PageQuery)], user: User, owner: User):
    print(page.page)
    print(page.page_size)
    print(user)
    print(owner)
    return {"owner": owner}


@user.get('/{pk}')
def get_user(pk: Annotated[int, Path(title='THE PK of the user to get', gt=0)]):
    print(type(pk))
    return {"message": f"get_user Hello World {pk}"}
